package org.naxx.security.model.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.naxx.security.algorithm.PolicyCombinigAlgorithm;
import org.naxx.security.model.Policy;
import org.naxx.security.model.PolicySet;
import org.naxx.security.model.Target;

/**
 * Two policy sets are equal if they have same id.
 */
public class PolicySetImpl implements PolicySet {
	
	private String description;
	private List<Policy> policies;
	private PolicyCombinigAlgorithm policyCombiningAlgorithm;
	private String id;
	private List<PolicySet> policySets;
	private Set<String> referencedPolicies;
	private Set<String> referencedPolicySet;
	private Target target;
	private String version;

	public PolicySetImpl() {
		this.policies = new ArrayList<Policy>();
		this.policySets = new ArrayList<PolicySet>();
		this.referencedPolicies = new HashSet<String>();
		this.referencedPolicySet = new HashSet<String>();
	}

	public PolicySetImpl(String description, List<Policy> policies, PolicyCombinigAlgorithm policyCombiningAlgorithm, 
			String id, List<PolicySet> policySets, Set<String> referencedPolicies, Set<String> referencedPolicySet, 
				Target target, String version) {
		this.description = description;
		this.policies = policies;
		this.policyCombiningAlgorithm = policyCombiningAlgorithm;
		this.id = id;
		this.policySets = policySets;
		this.referencedPolicies = referencedPolicies;
		this.referencedPolicySet = referencedPolicySet;
		this.target = target;
		this.version = version;
	}

	public String getDescription() {
		return this.description;
	}

	public List<Policy> getPolicies() {
		return this.policies;
	}

	public PolicyCombinigAlgorithm getPolicyCombiningAlgorithm() {
		return this.policyCombiningAlgorithm;
	}

	public String getId() {
		return this.id;
	}

	public List<PolicySet> getPolicySets() {
		return this.policySets;
	}

	public Set<String> getReferencedPolicies() {
		return this.referencedPolicies;
	}

	public Set<String> getReferencedPolicySets() {
		return this.referencedPolicySet;
	}

	public Target getTarget() {
		return this.target;
	}

	public String getVersion() {
		return this.version;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setPolicyCombiningAlgorithm(
			PolicyCombinigAlgorithm policyCombiningAlgorithm) {
		this.policyCombiningAlgorithm = policyCombiningAlgorithm;
	}

	public void setTarget(Target target) {
		this.target = target;
	}

	public void setVersion(String version) {
		this.version = version;
	}
	
	public void addPolicy(Policy policy) {
		this.policies.add(policy);
	}
	public void addPolicySet(PolicySet policySet) {
		this.policySets.add(policySet);
	}
	public void addReferencedPolicy(String referencedPolicy) {
		this.referencedPolicies.add(referencedPolicy);
	}
	public void addReferencedPolicySet(String referencedPolicySet) {
		this.referencedPolicySet.add(referencedPolicySet);
	}
	
	public boolean equals(Object obj) {
		if (this == obj) {
		    return true;
		}
		if (obj instanceof PolicySet) {
			PolicySet rhs = (PolicySet) obj;
			return this.id.equals(rhs.getId());
		}
		return false;
	}

	public int hashCode() {
		return this.id.hashCode();
	}
}
